/*
 * PhoneDict: A J2ME Dict client
 * 
 * Copyright (C) 2006 Labeneator labeneator@gmail.org
 *
 * This file is a part of PhoneDict. PhoneDict is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the Free 
 * Software Foundation; either version 2 of the License, or (at your option) any later version.
 * Mobber is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 */

import javax.microedition.io.*;
import java.io.*;
import dict.*;


public class SrvStatus extends Thread
{
	String server, port, dict, word;
	DictAsk writer;
	DictGet reader;
	StreamConnection connection;
	
	SrvStatus(String server, String port)
	{
		this.server = server;
		this.port = port;		
		start();
	}
	public void run(){
		try {
			this.connection = (StreamConnection)Connector.open("socket://" + server + ":" + port);
			this.writer = new DictAsk(this.connection.openOutputStream());
			this.reader = new DictGet(this.connection.openInputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try{
			System.out.println("Server Status");
			String welcome = reader.getWelcome();
			PhoneDict.logger.logging(welcome);
			System.out.println(welcome);
			writer.askServerStatus();
			String srvstatus = reader.getServerStatus();
			System.out.println(srvstatus);
			//PhoneDict.display.setCurrent(PhoneDict.show);
			PhoneDict.logger.logging("Server Status",srvstatus);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			// failed to write data
			//connectionFailed();
		}
	}
};
